/*
 * AALAction.h
 *
 *  Created on 09.08.2011
 *      Author: sili
 */

#ifndef AALACTION_H_
#define AALACTION_H_

#include <time.h>
#include <string>
#include <vector>

using namespace std;


enum ActionType{doLog, doShow, doInfo, doWarn, doAlarm, doHide, doSetValue, doImport, doTemplate,
				doPlayAudio, doReaload};

enum ActionState{inProgress, failed, done};

class AALItem;
class Controller;

class AALAction{
private:
	Controller * controller;
	string name;						// Action name e.g.
	time_t timestamp;					// The Creation time. Needed to deside if timeToLive is already over
	int timeToLive;						// Defines how log this action lives. A value of -1 means forever.
public:
	AALAction(const ActionType _actionType, AALItem * _aalItem, const char * _message, int _timeToLive = 0, Controller * _controller = NULL);
	virtual ~AALAction();
	const char * typeToString();
	long id;							// Action id
	ActionType type;					// ActionType, see enum above
	ActionState state;					// ActionState, see enum above
	string message;						// The message e.g. an Wanring with a message "Die Eingangstuer ist offen."
	string data;						// Action data. e.g. the TTS - WAV audiofile location which was generated from this message string.
	AALItem * aalItem;					// The AALItem which is responsible for this action
	vector<AALAction *> children;		// Action may have children. E.g. doAlarm-Action has a doPlayAudio child
	bool doReload;						// If this flag is true, the current 'shown' action needs to be realoaded.

	/**
	 * Reset the current timeToLive-Timer with the current time.
	 * Use the current time so that timeToLive starts from now on.
	 */
	void resetTimeToLiveTimer();

	/**
	 * Return true, if 'timestamp + timeToLive < now()'
	 */
	bool isAlive();
};
#endif /* AALACTION_H_ */
